#pragma once

#include "ReaderThread.h"
#include "DispatcherThread.h"
#include "McuRPCHandler.h"
#include "McuRPCSender.h"

namespace android {

class McuRPCManager {
public:
    enum RPC_HW_TYPE {
        RPC_SPI = 0,
        RPC_UART,
    };

    static McuRPCManager* getInstance();
    void notifyDataReady(int hw_type);
    void startSpiInput();
    void startUartInput();

    void registerSpiRPCHandler(McuRPCHandler* handler);
    void registerUartRPCHandler(McuRPCHandler* handler);

    int sendSpiMessage(int8_t* msg, int len);
    int sendUartMessage(int8_t* msg, int len);
private:
    McuRPCManager();
    ~McuRPCManager();

private:
    sp<ReaderThread> mSpiReader;
    sp<DispatcherThread> mSpiDispatcher;
    BufferQueue<McuRPCBuffer>* mSpiBufferQueue;

    sp<ReaderThread> mUartReader;
    sp<DispatcherThread> mUartDispatcher;
    BufferQueue<McuRPCBuffer>* mUartBufferQueue;

    McuRPCSender* mSpiSender;
    McuRPCSender* mUartSender;
    static McuRPCManager* mSingleton;
};

} //namespace

